package com.mages.aspect.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;

import java.sql.*;

@Component
public class ConcurrencyService {
    private static String redisHost;
    public int concurrentCount;

    @Value("${REDIS_HOST:localhost}")
    public void setRedisHost(String redisHost) {
        this.redisHost = redisHost;
    }

    public Integer QueryConcurrency(){
        try {
            Jedis jedis = new Jedis(redisHost); // 默认端口为6379
            // 执行Redis命令
            int concurrentCount = Integer.parseInt(jedis.get("aspect_concurrency"));
            System.out.println("aspect_concurrency: " + concurrentCount);
            // 关闭连接
            jedis.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return concurrentCount;
    }
}
